﻿<UserControl
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:c="clr-namespace:SqlMiM.Controls"
  xmlns:a="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
    xmlns:conv="clr-namespace:SqlMiM.Common.Converters;assembly=SqlMiM.Common"
  xmlns:k="clr-namespace:SqlMiM"
  x:Name="This"
  x:Class="SqlMiM.Views.SummaryView"
  mc:Ignorable="d">

    <UserControl.Resources>

        <ResourceDictionary>

            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/SqlMiM.Common;component/Resources/ControlsTheme.xaml" />

            </ResourceDictionary.MergedDictionaries>

            <CollectionViewSource Source="{Binding Groups}" x:Key="GroupsView">
                <CollectionViewSource.SortDescriptions>
                    <scm:SortDescription PropertyName="Index" Direction="Ascending" />
                </CollectionViewSource.SortDescriptions>
            </CollectionViewSource>
            
            <!--ListBoxItem Style-->
            <Style  x:Key="listBoxItemStyle" TargetType="{x:Type ListBoxItem}">
                <Setter Property="Cursor" Value="Hand" />
                <Setter Property="Margin" Value="0" />
                <Setter Property="HorizontalAlignment" Value="Stretch" />
                <!--<Setter Property="ContextMenu" Value="{DynamicResource SnippetContextMenu}" />-->
                <Setter Property="OverridesDefaultStyle" Value="True" />
                <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                <Setter Property="Foreground" Value="{DynamicResource Foreground}" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListBoxItem}">
                            <Border HorizontalAlignment="Stretch" x:Name="Border" Background="Transparent" >
                                <ContentPresenter VerticalAlignment="Center" Margin="0,0,0,0" HorizontalAlignment="Stretch" />
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="Border" Property="Background" Value="#20FFFFFF" />
                                    <Setter Property="Foreground" Value="{DynamicResource Foreground}" />
                                </Trigger>
                            </ControlTemplate.Triggers>

                        </ControlTemplate>

                    </Setter.Value>
                </Setter>
            </Style>

            <!-- DataTemplate x:Key="linkTemplate" -->
            <DataTemplate x:Key="linkTemplate">
                <Button VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="0" Height="20" 
                        ToolTip="{Binding Description}" Click="Button_Click">
                    <Button.Template>
                        <ControlTemplate>
                            <DockPanel LastChildFill="True" IsHitTestVisible="True" Background="Transparent" >
                                <Image DockPanel.Dock="Left" VerticalAlignment="Center" Margin="20,5,5,0" Source="{Binding Icon}" Width="14" />
                                <TextBlock VerticalAlignment="Center" Text="{Binding Name}" Foreground="{DynamicResource Foreground}" />
                            </DockPanel>
                        </ControlTemplate>

                    </Button.Template>
                </Button>
            </DataTemplate>

            <!-- DataTemplate x:Key="categoryTemplate" -->
            <DataTemplate x:Key="categoryTemplate">
                <Expander Margin="5" IsExpanded="True" HorizontalContentAlignment="Stretch"  >

                    <Expander.Header>
                        <Grid VerticalAlignment="Center" Margin="0" Height="20" IsHitTestVisible="True" >
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <TextBlock  Grid.Column="1" Foreground="{DynamicResource Foreground}"  HorizontalAlignment="Left" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" 
                                       Text="{Binding Name}" />
                            <Image Grid.Column="0" Margin="0,0,5,0"  HorizontalAlignment="Right" Source="{Binding Path=Icon}" />
                        </Grid>
                    </Expander.Header>

                    <ListBox VerticalAlignment="Stretch" FocusVisualStyle="{x:Null}" TextElement.Foreground="{DynamicResource Foreground}" 
                                HorizontalAlignment="Stretch"
                                ItemsSource="{Binding Plugins}" ItemTemplate="{StaticResource linkTemplate}" 
                                ItemContainerStyle="{StaticResource listBoxItemStyle}">
                        <ListBox.Template>
                            <ControlTemplate>
                                <StackPanel Margin="0,0,0,0" IsItemsHost="true" />
                            </ControlTemplate>
                        </ListBox.Template>
                    </ListBox>

                </Expander>

            </DataTemplate>

        </ResourceDictionary>

    </UserControl.Resources>


    <Grid MinHeight="15" Margin="0,5" Background="Transparent" x:Name="MainGrid" >

        <ItemsControl ItemsSource="{Binding Source={StaticResource GroupsView}}"
              ItemTemplate="{StaticResource categoryTemplate}"
              Grid.ColumnSpan="2">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Vertical" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>


    </Grid>


</UserControl>
